﻿using System;
using UnityEngine;

namespace Assets.Core
{
    /// <summary>
    /// Represents a bunch of blocks
    /// </summary>
    public class Chunk
    {
        public Chunk()
        {
            chunkData = new Block[WIDTH, HEIGHT, DEPTH];
        }

        public const byte WIDTH = 8;
        public const byte HEIGHT = 8;
        public const byte DEPTH = 8;

        private Block[, ,] chunkData;

        /// <summary>
        /// returns a 3D block(type) array
        /// </summary>
        public Block[, ,] ChunkData
        {
            get
            {
                return chunkData;
            }
        }

        /// <summary>
        /// Returns true if the place is empty
        /// </summary>
        /// <param name="_x">X Coordinate in the Chunk</param>
        /// <param name="_y">Y Coordinate in the Chunk</param>
        /// <param name="_z">Z Coordinate in the Chunk</param>
        /// <returns></returns>
        public bool IsEmpty(byte _x, byte _y, byte _z)
        {
            if (UtilsManager.CheckIndexOfArray(chunkData, _x, _y, _z))
            {
                Debug.LogWarning(String.Format("Block: {0};{1};{2} is outside the bounds", _x, _y, _z));
                return false;
            }

            return chunkData[_x, _y, _z] == null ? true : false;
        }
    }
}
